import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import { Park } from './park';
import { Header } from 'ionic-angular';

/*
  Generated class for the ParkDataProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class ParkDataProvider {
  private readonly baseUrl: string = 'https://api.bmob.cn/1';
  private readonly httpHeaders : HttpHeaders = new HttpHeaders({
    'X-Bmob-Application-Id':'75e754ba6f90979b675a99df80788ff4',
    'X-Bmob-REST-API-Key':'7ebc7f41ac2d842920b7a79a005083a9',
    'Content-Type':'application/json'
 });


  constructor(public http: HttpClient) {
    
  }

  /**
   * 分页获取景区数据
   * @param num 
   * @param page 
   */

  getParks(num: number, page: number): Observable<Park[]>{
    let _params  = new HttpParams()
    .set('limit', `${num}`)
    .set('skip', `${(page - 1)* num}`);
    return this.http.get<Park[]>(`${this.baseUrl}/classes/parks`,
    { headers: this.httpHeaders, params: _params }).map(_=>_['results']);

  }

}
